{% extends 'user/user_base.html' %}


{% block form %}


    <form action="" method="post">
        {% csrf_token %}
        <div class="form-group">
            {{ form.email.label_tag }}
            {{ form.email }}

            {% if form.email.errors %}
                {% for error in form.email.errors %}
                    <p class="text-danger">{{ error }}</p>
                {% endfor %}
            {% endif %}
        </div>
        <div class="form-group">
            {{ form.password.label_tag }}
            {{ form.password }}
            {% if form.password.errors %}
                {% for error in form.password.errors %}
                    <p class="text-danger">{{ error }}</p>
                {% endfor %}
            {% endif %}
        </div>
        <div class="form-group">
            {{ form.password2.label_tag }}
            {{ form.password2 }}
            {% if form.password2.errors %}
                {% for error in form.password2.errors %}
                    <p class="text-danger">{{ error }}</p>
                {% endfor %}
            {% endif %}
        </div>

        <div class="form-group">
            {{ form.captcha.label_tag }}
            {{ form.captcha }}
            {% if form.captcha.errors %}
                {% for error in form.captcha.errors %}
                    <p class="text-danger">{{ error }}</p>
                {% endfor %}
            {% endif %}
        </div>

        <button type="submit" class="btn btn-default">注册</button>
        <a href="{% url 'user:login' %}" class="btn btn-default" role="button">已有账号去登录</a>
    </form>

{% endblock %}

{% block js %}
    <script>
        $('.captcha').click(function () {
            $.getJSON("/captcha/refresh/", function (result) {
                $('.captcha').attr('src', result['image_url']);
                $('#id_captcha_0').val(result['key'])
            });
        });
    </script>
{% endblock %}
